/*     */ package com.zimbra.cs.mailbox;
/*     */ 
/*     */ import com.google.common.base.Objects;
/*     */ import com.google.common.base.Objects.ToStringHelper;
/*     */ import com.zimbra.common.mailbox.Color;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.db.DbMailItem;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class Comment
/*     */   extends MailItem
/*     */ {
/*     */   private String mCreatorId;
/*     */   
/*     */   Comment(Mailbox mbox, MailItem.UnderlyingData data)
/*     */     throws ServiceException
/*     */   {
/*  30 */     this(mbox, data, false);
/*     */   }
/*     */   
/*     */   Comment(Mailbox mbox, MailItem.UnderlyingData data, boolean skipCache) throws ServiceException {
/*  34 */     super(mbox, data, skipCache);
/*     */   }
/*     */   
/*     */   public static Comment create(Mailbox mbox, MailItem parent, int id, String uuid, String text, String creatorId, MailItem.CustomMetadata custom) throws ServiceException {
/*  38 */     if (!(parent instanceof Document)) {
/*  39 */       throw MailServiceException.CANNOT_PARENT();
/*     */     }
/*  41 */     MailItem.UnderlyingData data = new MailItem.UnderlyingData();
/*  42 */     data.uuid = uuid;
/*  43 */     data.id = id;
/*  44 */     data.type = MailItem.Type.COMMENT.toByte();
/*  45 */     data.folderId = 17;
/*  46 */     data.parentId = parent.mId;
/*  47 */     data.setSubject(text);
/*  48 */     data.date = mbox.getOperationTimestamp();
/*  49 */     data.size = text.length();
/*  50 */     data.metadata = encodeMetadata(DEFAULT_COLOR_RGB, 1, 1, creatorId, custom);
/*  51 */     data.contentChanged(mbox);
/*     */     
/*  53 */     new DbMailItem(mbox).create(data);
/*  54 */     Comment comment = new Comment(mbox, data);
/*  55 */     comment.finishCreation(parent);
/*     */     
/*  57 */     return comment;
/*     */   }
/*     */   
/*     */   public String getSender()
/*     */   {
/*  62 */     return "";
/*     */   }
/*     */   
/*     */   boolean isTaggable()
/*     */   {
/*  67 */     return true;
/*     */   }
/*     */   
/*     */   boolean isCopyable()
/*     */   {
/*  72 */     return true;
/*     */   }
/*     */   
/*     */   boolean isMovable()
/*     */   {
/*  77 */     return true;
/*     */   }
/*     */   
/*     */   boolean isMutable()
/*     */   {
/*  82 */     return false;
/*     */   }
/*     */   
/*     */ 
/*     */   boolean canHaveChildren()
/*     */   {
/*  88 */     return false;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public String getText()
/*     */   {
/*  97 */     return getSubject();
/*     */   }
/*     */   
/*     */   public String getCreatorAccountId() {
/* 101 */     return this.mCreatorId;
/*     */   }
/*     */   
/*     */   public Account getCreatorAccount() throws ServiceException {
/* 105 */     Provisioning prov = Provisioning.getInstance();
/* 106 */     return prov.getAccountById(this.mCreatorId);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   protected boolean hasFullPermission(Account authuser)
/*     */   {
/* 114 */     if ((authuser != null) && (authuser.getId().equals(this.mCreatorId)))
/* 115 */       return true;
/* 116 */     return super.hasFullPermission(authuser);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   Metadata encodeMetadata(Metadata meta)
/*     */   {
/* 123 */     return encodeMetadata(meta, this.mRGBColor, this.mMetaVersion, this.mVersion, this.mCreatorId, this.mExtendedData);
/*     */   }
/*     */   
/*     */   private static String encodeMetadata(Color color, int metaVersion, int version, String accountId, MailItem.CustomMetadata custom) {
/* 127 */     MailItem.CustomMetadata.CustomMetadataList extended = custom == null ? null : custom.asList();
/* 128 */     return encodeMetadata(new Metadata(), color, metaVersion, version, accountId, extended).toString();
/*     */   }
/*     */   
/*     */   private static Metadata encodeMetadata(Metadata meta, Color color, int metaVersion, int version, String accountId, MailItem.CustomMetadata.CustomMetadataList extended) {
/* 132 */     meta.put("cr", accountId);
/* 133 */     return encodeMetadata(meta, color, null, metaVersion, version, extended);
/*     */   }
/*     */   
/*     */   void decodeMetadata(Metadata meta) throws ServiceException
/*     */   {
/* 138 */     super.decodeMetadata(meta);
/* 139 */     if (meta == null)
/* 140 */       return;
/* 141 */     this.mCreatorId = meta.get("cr");
/*     */   }
/*     */   
/*     */   public String toString()
/*     */   {
/* 146 */     Objects.ToStringHelper helper = Objects.toStringHelper(this);
/* 147 */     appendCommonMembers(helper);
/* 148 */     helper.add("type", getType());
/* 149 */     helper.add("creator", this.mCreatorId);
/* 150 */     helper.add("text", getSubject());
/*     */     try {
/* 152 */       helper.add("parent", getParent());
/*     */     }
/*     */     catch (ServiceException e) {}
/* 155 */     return helper.toString();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailbox/Comment.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */